package in.co.codedoc.sql;


public class Table
{
	public Table(String tableName)
	{
		this.tableName = tableName;
	}
	
	public Table(Table wrappedTable,String alias)
	{
		this.wrappedTable = wrappedTable;
		this.alias = alias;
	}

	public String GetTableName()
	{
		return HasAlias() ? wrappedTable.GetTableName() : tableName;
	}
	
	public boolean HasAlias()
	{
		return alias != null;
	}
	
	public String GetAlias()
	{
		return alias;
	}
	
	public int hashCode()
	{
		return
			HasAlias()
			?
				alias.hashCode() ^ wrappedTable.hashCode()
			:
				tableName.hashCode()
			;
	}
	
	public boolean equals(Object t)
	{
		if(t== null || !(t instanceof Table))
		{
			return false;
		}
		
		Table that = (Table) t;
		
		return
			(
				(that.HasAlias() && HasAlias())
				||
				!(that.HasAlias() || HasAlias())
			)
			&&
			(
				HasAlias()
				?
					(alias.equals(that.alias) && wrappedTable.equals(that.wrappedTable))
				:
					tableName.equals(that.tableName)
			);
	}
	
	private String tableName;
	private Table wrappedTable;
	private String alias;
}

